<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 *
 * 后台管理员控制器
 * @author 66diqiu-li
 *
 */
class Admin_Adminuser_module extends CI_Module {

	/**
	 *
	 * 构造函数
	 */
	public function __construct(){
		parent::__construct();
			
		$this->load->model('admin.Adminuser_model');
		$this->load->model('admin.Adminrole_model');
		$this->load->model('expert.Expert_model');
		$this->load->model('admin.Adminusercashmsg_model');
	}

	/**
	 *
	 * 管理员列表
	 */
	function index(){
		//查询条件
//		$condition = $this->input->post('condition')?$this->input->post('condition'):$this->input->get('condition');
		$this->load->library('mycommonclass');
//        $where = $this->mycommonclass->str2where($condition);

        $condition = array();
        $condition['name'] = $this->input->get_post('keywords');
        $condition['role_id'] = $this->input->get_post('role_id');
        $condition['division_id'] = $this->input->get_post('division_id');//部门
        if($condition['division_id']===false){
            $parent_id = $condition['division_id'] = -1;
        }

        $this->load->library('mytreeclass');
        $parent_id = $condition['division_id'] =  $condition['division_id']?$condition['division_id']:0;
        $result = $this->Adminuser_model->division_list();
        $array = array();
        foreach($result as $r){
            $r['selected'] = $r['id']==$parent_id ? 'selected':'';
            $array[] = $r;
        }
        $this->mytreeclass->init($array);
        $str = "<option value='\$id' \$selected>\$spacer \$name</option>";
        $select_categorys = $this->mytreeclass->get_tree(0, $str);
        $data['select_categorys'] = $select_categorys;

        $table = $this->db->dbprefix('admin_user');
        $table_division = $this->db->dbprefix('division');
        $where = " $table.sid=$GLOBALS[sid] ";
        if($condition['name'])$where.= " and $table.name='".addslashes($condition[name])."' ";
        ;
        if($condition['role_id'])$where.= " and $table.role_id=$condition[role_id] ";
        if($parent_id!=-1&&$parent_id!=0){
            $where.= " and $table.division_id in (select id from $table_division where find_in_set($parent_id,code) )";
        }
        if($parent_id==0){
            $where.= " and $table.division_id=0 ";
        }
		$page_config['perpage']=20;   //每页条数
		$page_config['part']=2;//当前页前后链接数量
		$page_config['url']='admin/adminuser/index';//url
		$page_config['param'] = '?name='.$condition['name'].'&role_id='.$condition['role_id'].'&division_id='.$parent_id;//参数
		$page_config['seg']=4;//参数取 index.php之后的段数，默认为3，即index.php/control/function/18 这种形式
		$page_config['nowindex']=$this->uri->segment($page_config['seg']) ? $this->uri->segment($page_config['seg']):1;//当前页
		$page_config['total'] = $this->Adminuser_model->get_count($where);
		$this->load->library('mypageclass');
		$this->mypageclass->initialize($page_config);
		$result = $this->Adminuser_model->get_list($page_config['perpage'],$page_config['nowindex'],$where);
        foreach ($result as $k => $v) {
            if($this->Site_model->get_site_info_by_adminname($v['name'], $GLOBALS['sid'])){
                $result[$k]['disable'] = 1;
                break;
            }
        }

        $data['list'] = $result;
		$data['condition'] = $condition;
        $role_list = $this->Adminrole_model->get_usable_list();
        $data['role_list'] = $role_list;
        $data['index_url'] = site_url('admin/adminuser/index');
		$this->load->view('adminuser/adminuser_index',$data);
	}

	/**
	 *
	 * 管理员添加页面
	 */
	function add(){
		$this->load->library('mytreeclass');
		$parent_id = 0;
		$result = $this->Adminuser_model->division_list();
		$array = array();
		$data['wmp'] = $this->input->get('type')?1:0;
		foreach($result as $r){
			$r['selected'] = $r['id']==$parent_id ? 'selected':'';
			$array[] = $r;
		}

		$data['daren'] = $this->Adminrole_model->get_row(array('name'=>'达人','sid'=>$this->$GLOBALS['sid']),'id');


		$this->mytreeclass->init($array);
		$str = "<option value='\$id' \$selected>\$spacer \$name</option>";
		$select_categorys = $this->mytreeclass->get_tree(0, $str);
		$data['select_categorys'] = $select_categorys;
		//数据保存URL
		$data['form_post'] = site_url('admin/adminuser/save');
		$data['ajax_check_name'] = site_url('admin/adminuser/ajax_check_name?id=0');
		$data['ajax_check_email'] = site_url('admin/adminuser/ajax_check_email?id=0');
		$data['ajax_check_mobile'] = site_url('admin/adminuser/ajax_check_mobile?id=0');

		//角色列表
		$role_list = $this->Adminrole_model->get_usable_list();
		$data['role_list'] = $role_list;

		$this->load->view('adminuser/adminuser_add',$data);
	}

	/**
	 *
	 * 管理员编辑页面
	 */
	function edit(){
		$this->load->library('mytreeclass');
		$id = $this->input->get('id');
		$row = $this->Adminuser_model->get_row(array('id'=>$id));
		$data['row'] = $row;
		$parent_id = $row['division_id'];
		$result = $this->Adminuser_model->division_list();
		$array = array();
		foreach($result as $r){
			$r['selected'] = $r['id']==$parent_id ? 'selected':'';
			$array[] = $r;
		}
		$this->mytreeclass->init($array);
		$str = "<option value='\$id' \$selected>\$spacer \$name</option>";
		$select_categorys = $this->mytreeclass->get_tree(0, $str);
		$data['select_categorys'] = $select_categorys;

		//数据保存URL
		$data['form_post'] = site_url('admin/adminuser/save');
		$data['ajax_check_name'] = site_url("admin/adminuser/ajax_check_name?id=$id");
		$data['ajax_check_email'] = site_url("admin/adminuser/ajax_check_email?id=$id");
		$data['ajax_check_mobile'] = site_url("admin/adminuser/ajax_check_mobile?id=$id");

		//角色列表
		$role_list = $this->Adminrole_model->get_usable_list();
		$data['role_list'] = $role_list;

        //检查管理员是否是 创始人
        if($this->Site_model->get_site_info_by_adminname($row['name'], $GLOBALS['sid'])){
//            $data['disable'] = 1;
        }

		$this->load->view('adminuser/adminuser_edit',$data);
	}

	/**
	 *
	 * 管理员保存操作
	 */
	function save(){
		$data = $this->input->post('Form');
		$id = $this->input->post('id');
		if(empty($id)){
			//操作日志
			$log = array('action' => 'add');

            $row = $this->Adminuser_model->get_row(array('name'=>addslashes($data['name'])));
            if(!empty($row) && is_array($row)) {
                $this->error('此管理员名称已存在!', '', true);
            }
			$data['password'] = md5($data['password']);
			$data['add_time'] = date('Y-m-d H:i:s',now());
			$res = $this->Adminuser_model->add_row($data);

            //达人
            $this->Expert_model->expert_add($res);
		}else{
			if(empty($data['password'])){
				unset($data['password']);
			}else{
				$data['password'] = md5($data['password']);
			}
			//操作日志
			$log = array('action' => 'edit');
			$res = $this->Adminuser_model->edit_row($data,array('id'=>$id));

			if($res){//添加达人记录
				//达人
				if(!$this->Expert_model->check_exists_expert_by_id($res))
				{
					$this->Expert_model->expert_add($res);
				}
			}
		}

        if($this->input->get('inajax')){
            $returl = '';
        }else{
            $returl = site_url('admin/adminuser/index');
        }
		if($res){
			//操作日志添加
			$log['log'] = '后台管理员('.$data['name'].')';
			$this->_record_log($log);

			$this->success('操作成功', $returl, true);
		}else{
			$this->error('操作失败', $returl, true);
		}
	}

	/**
	 *
	 * 删除操作
	 */
	function ajax_remove(){
        $id = intval($this->input->get('id'));
		if(empty($id)){
			$post_id = $this->input->post('id');
            foreach (explode(',', $post_id) as $k => $v) {
                $post_ids[] = intval($v);
            }
            $post_id = implode(',', $post_ids);

            if($post_id){
                $where = "id in ($post_id) and sid = {$GLOBALS['sid']} ";
                $res = $this->Adminuser_model->remove_row($where);
                $this->Expert_model->_delete_expert("id in ($post_id)");
            }
		}else{
			$res = $this->Adminuser_model->remove_row(array('id'=>$id,'sid'=>$GLOBALS['sid']));
            $this->Expert_model->_delete_expert(array('id'=>$id));
		}

        if($this->input->get('inajax')){
            $returl = '';
        }else{
            $returl = site_url('admin/adminuser/index');
        }

		if($res){
			$this->success('操作成功',$returl,true);
		}else{
			$this->error('操作失败','',true);
		}
	}

	/**
	 *
	 * 修改状态信息
	 */
	function ajax_status(){
		$post = $this->input->post();
		$data[$post['field']] = $post['val'];
		$res = $this->Adminuser_model->edit_row($data,array('id'=>$post['id']));
		if($res){

			//操作日志
			$row = $this->Adminuser_model->get_row(array('id'=>$post['id']),'name');
			$log = array('action'=>'edit','log'=>'后台管理员('.$row['name'].')-状态值');
			$this->_record_log($log);

			$this->success('操作成功','',true);
		}else{
			$this->error('操作失败','',true);
		}
	}

	/**
	 *
	 * 判断管理员的名称是否存在
	 */
	function ajax_check_name(){
		$arg_get = $this->input->get();
        $username = $arg_get['username'];
        if(!$username){
            $username = $arg_get['Form']['name'];
        }
		$row = $this->Adminuser_model->get_row(array('name'=>addslashes($username),'id !='=>intval($arg_get['id'])));
		if(!empty($row) && is_array($row)){
			$this->ajaxReturn('此管理员名称已存在!');
		}else{
			$this->ajaxReturn(true);
		}
	}

	/**
	 * 修改用户信息
	 */
	public function change_pass(){
		$id = $this->session->userdata('admin_user_id');
		$row = $this->Adminuser_model->get_row(array('id'=>$id));
		if(empty($row)){
			$this->error('信息错误!',site_url('admin/index/index'),1);
		}
		$data['row'] = $row;
		//数据保存URL
		$data['form_post'] = site_url('admin/adminuser/change_pass_save');
		$data['ajax_check_pass'] = site_url("admin/adminuser/ajax_check_pass");

		$this->load->view('adminuser/change_pass',$data);
	}

	/**
	 *
	 * 管理员密码保存操作
	 */
	function change_pass_save(){
		$data = $this->input->post('Form');
		$id = $this->session->userdata('admin_user_id');
		$row = $this->Adminuser_model->get_row(array('id'=>$id));
		if(empty($id)){
			$this->error('信息错误!',site_url('admin/index/index'),1);
		}else{
			$update_data = array();
			$update_data['password'] = md5($data['password']);
			//操作日志
			$log = array('action' => 'edit');
			$res = $this->Adminuser_model->edit_row($update_data,array('id'=>$id));
		}
		if($res){

			//操作日志添加
			$log['log'] = '后台管理员('.$row['name'].'):修改密码';
			$this->_record_log($log);

			if($this->Adminuser_model->logout()){
				$this->success('修改密码成功,请重新登陆！', site_url("admin/index/login"),true);
			}
		}else{
			$this->error('操作失败',site_url('admin/adminuser/index'),true);
		}
	}

	/**
	 * 判断旧密码是否正确
	 */
	function ajax_check_pass(){
		$id = $this->session->userdata('admin_user_id');
		$arg_get = $this->input->get();
		$password = $arg_get['oldpassword'];
		if(!$password){
			$password = $arg_get['Form']['old_password'];
		}
		$row = $this->Adminuser_model->get_row(array('password'=>md5($password),'id'=>$id));
		if(!empty($row) && is_array($row)){
			$this->ajaxReturn(true);
		}else{
			$this->ajaxReturn('旧密码输入错误!');
		}
	}

	/**
	 *
	 * 判断管理员的email地址是否存在
	 */
	function ajax_check_email(){
		$arg_get = $this->input->get();
		$row = $this->Adminuser_model->get_row(array('email'=>$arg_get['Form']['email'],'id !='=>$arg_get['id']));
		if(!empty($row) && is_array($row)){
			$this->ajaxReturn('此E-mail地址已存在!');
		}else{
			$this->ajaxReturn(true);
		}
	}

	/**
	 *
	 * 判断管理员的手机号码是否存在
	 */
	function ajax_check_mobile(){
		$arg_get = $this->input->get();
        $mobile = $arg_get['mobile'];
        if(!$mobile){
            $mobile = $arg_get['Form']['mobile'];
        }
        $mobile = addslashes($mobile);
        if(!preg_match("/1[34578]{1}\d{9}$/",$mobile)){
            $this->ajaxReturn('手机号码格式不正确!');
        }
		$row = $this->Adminuser_model->get_row(array('mobile'=>$mobile,'id !='=>intval($arg_get['id'])));
		if(!empty($row) && is_array($row)){
			$this->ajaxReturn('此手机号码已存在!');
		}else{
			$this->ajaxReturn(true);
		}
	}

	/**
	 *
	 * 部门管理
	 */
	function division(){
		//引入树形类
		$this->load->library('mytreeclass');
		$result = $this->Adminuser_model->division_list();
		$this->mytreeclass->icon = array('&nbsp;&nbsp;&nbsp;│ ', '&nbsp;&nbsp;&nbsp;├─ ', '&nbsp;&nbsp;&nbsp;└─ ');
		$this->mytreeclass->nbsp = '&nbsp;&nbsp;&nbsp;';
		$this->mytreeclass->init($result);
		$str = "<tr><td class='btn_min'>
		            <div class='operat hidden'>
		                <a class='icon-cog action' href='javascript:;'>处理</a>
		                <div class='menu_select'>
		                    <ul>
		                        <li><a class='icon-pencil' href='".site_url('admin/adminuser/division_edit?id=$id')."'>编辑</a></li>
		                        <li><a class='icon-remove-2 doDel' href='javascript:;' data-uri='".site_url('admin/adminuser/division_remove?id=$id')."'>删除</a></li>
		                    </ul>
		                </div>
		            </div>
		        </td><td>\$spacer\$name</td></tr>";
		$select_categorys = $this->mytreeclass->get_tree(0, $str);
		$data['select_categorys'] = $select_categorys;
		$this->load->view('adminuser/division_index',$data);
	}
	function division_add(){
		//引入树形类
		$this->load->library('mytreeclass');
		$parent_id = 0;
		$result = $this->Adminuser_model->division_list();
		$array = array();
		foreach($result as $r){
			$r['selected'] = $r['id']==$parent_id ? 'selected':'';
			$array[] = $r;
		}
		$this->mytreeclass->init($array);
		$str = "<option value='\$id' \$selected>\$spacer \$name</option>";
		$select_categorys = $this->mytreeclass->get_tree(0, $str);
		$data['select_categorys'] = $select_categorys;

		//数据保存URL
		$data['form_post'] = site_url('admin/adminuser/division_save');
		$this->load->view('adminuser/division_add',$data);
	}
	function division_edit(){
		$id = $this->input->get('id');
		//引入树形类
		$this->load->library('mytreeclass');
		$row = $this->Adminuser_model->division_row(array('id'=>$id));
		$parent_id = $row['parent_id'];
		$result = $this->Adminuser_model->division_list();
		$array = array();
		foreach($result as $r){
			$r['selected'] = $r['id']==$parent_id ? 'selected':'';
			$array[] = $r;
		}
		$this->mytreeclass->init($array);
		$str = "<option value='\$id' \$selected>\$spacer \$name</option>";
		$select_categorys = $this->mytreeclass->get_tree(0, $str);
		$data['select_categorys'] = $select_categorys;
		$data['row'] = $row;
		//数据保存URL
		$data['form_post'] = site_url('admin/adminuser/division_save');
		$this->load->view('adminuser/division_edit',$data);
	}
	function division_save(){
		$data = $this->input->post('Form');
		$id = $this->input->post('id');
		if(empty($id)){
			//操作日志
			$log = array('action' => 'add');
			$res = $this->Adminuser_model->division_add($data);
			$this->Adminuser_model->update_code($res,$data['parent_id']);
		}else{
			//操作日志
			$log = array('action' => 'edit');
			$res = $this->Adminuser_model->division_edit($data,array('id'=>$id));
			$this->Adminuser_model->update_code($id,$data['parent_id']);
		}
		if($res){

			//操作日志添加
			$log['log'] = '后台管理菜单-'.$data['name'];
			$this->_record_log($log);

			$this->success('操作成功',site_url('admin/adminuser/division'),true);
		}else{
			$this->error('操作失败',site_url('admin/adminuser/division'),true);
		}
	}
	/**
	 *
	 * 删除操作
	 */
	function division_remove(){
		$id = $this->input->get('id');

		//判断是否有子菜单
		$is_has_child = $this->Adminuser_model->is_has_child($id);
		if($is_has_child){
			$this->error('该菜单存在子菜单,请先删除其子菜单!','',true);
		}
		//查询菜单名称
		$row = $this->Adminuser_model->division_row(array('id'=>$id),'name');
		$res = $this->Adminuser_model->division_remove(array('id'=>$id));
		if($res){
			//操作日志
			$log = array('action'=>'remove','log'=>'部门管理('.$row['name'].')');
			$this->_record_log($log);
			$this->success('操作成功','',true);
		}else{
			$this->error('操作失败','',true);
		}
	}

	/**
	 *
	 * 编辑部门权限
	 */
	function division_auth(){
		$id = $this->input->get_post('id');
		$priv = $this->Adminuser_model->get_row(array('id'=>$id),'authority,name');
		$priv_data = explode(",",$priv['authority']);//已有权限

		$result = $this->Adminuser_model->division_list();

		$json = array();
		foreach ($result as $rs) {
			$data = array(
                'id' => $rs['id'],
                'parent_id' => $rs['parent_id'],
                'name' => $rs['name'],
                'checked' => in_array($rs['id'], $priv_data)?'true':'false',
                'open' => true,
			);
			$json[] = $data;
		}
		$data = array(
    	    'json'=>json_encode($json),
    	    'id' => $id,
		);
		$data['name'] = $priv['name'];
		$data['form_post'] = site_url('admin/adminuser/save_auth');
		$this->load->view('adminuser/adminuser_authority',$data);
	}

	/**
	 *
	 * 部门权限的保存
	 */
	function save_auth(){
		$id = $this->input->get_post('id');
		$auth = $this->input->get_post('menu_id');
		$res = $this->Adminuser_model->edit_row(array('authority'=>$auth),array('id'=>$id));
		if($res){
			$log = array('action'=>'edit','log'=>'管理员权限('.$id.')');
			$this->_record_log($log);
			$this->success('授权成功!',site_url('admin/adminuser/index'),true);
		}else{
			$this->error('授权失败!',site_url('admin/adminuser/index'),true);
		}
	}

	/**
	 * 保证金 押金 表单页面
	 */
	public function cash_info(){
		$id = $this->input->get('id');
		$row = $this->Adminuser_model->get_row(array('id'=>$id));
		$data = array();
		$data['row'] = $row;
		$data['form_post'] = site_url('admin/adminuser/cash_save');
		$this->load->view('adminuser/cash_info',$data);
	}

	/**
	 * 保证金 押金 操作日志记录
	 */
	public function cash_list(){
		//查询条件
		$id = $this->input->get('id');
		$this->load->library('mycommonclass');
		$where = array('user_id'=>$id);
		$page_config['perpage']=20;   //每页条数
		$page_config['part']=2;//当前页前后链接数量
		$page_config['url']='admin/adminuser/cash_list';//url
		$page_config['param'] = '?id='.$id;//参数
		$page_config['seg']=4;//参数取 index.php之后的段数，默认为3，即index.php/control/function/18 这种形式
		$page_config['nowindex'] = $this->uri->segment($page_config['seg']) ? $this->uri->segment($page_config['seg']):1;//当前页
		$page_config['total'] = $this->Adminuser_model->get_cash_count($where);
		$this->load->library('mypageclass');
		$this->mypageclass->initialize($page_config);
		$result = $this->Adminuser_model->get_cash_list($page_config['perpage'],$page_config['nowindex'],$where);
		$data['list'] = $result;
		$data['cash_type_value'] = array('0'=>'','1'=>'保证金','2'=>'押金','3'=>'佣金');
		$data['type_value'] = array('0'=>'','1'=>'+','2'=>'-');
		$this->load->view('adminuser/cash_list',$data);
	}

	/**
	 * 保证金 押金 保存处理
	 */
	public function cash_save(){
		$arg_post = $this->input->post('Form');
		$arg_post['add_time'] = date('Y-m-d H:i:s',now());
		$arg_post['add_admin_id'] = $this->session->userdata('admin_user_id');
		$arg_post['add_admin_username'] = $this->session->userdata('admin_user_name');
		$arg_post['sid'] = $GLOBALS['sid'];
		$row = $this->Adminuser_model->get_row(array('id'=>$arg_post['user_id']));
		if($arg_post['type']=='2'){//消费
            if($arg_post['cash_type']==1){
                $error = ($row['cash_deposit']-$arg_post['money'])>=0?0:1;
			}elseif($arg_post['cash_type']==2){
				$error = ($row['cash_pledge']-$arg_post['money'])>=0?0:1;
			}
		}
		if($error==1){
			$this->error('余额不足!',null,true);
		}else{
			$res = $this->Adminuser_model->add_cash_log($arg_post);
			if($res){
				$this->success('操作成功!',site_url('admin/adminuser/cash_info?id='.$arg_post['user_id']),true);
			}else{
				$this->error('操作失败!',null,true);
			}
		}
	}

	/**
	 * 供应商保证金申请通知
	 */
	public function cash_msg(){
		$data = array();
		$this->load->library('mycommonclass');
		$where = array('sid'=>$GLOBALS['sid']);
		$page_config['perpage']=20;   //每页条数
		$page_config['part']=2;//当前页前后链接数量
		$page_config['url']='admin/adminuser/cash_msg';//url
		$page_config['param'] = '';//参数
		$page_config['seg']=4;//参数取 index.php之后的段数，默认为3，即index.php/control/function/18 这种形式
		$page_config['nowindex'] = $this->uri->segment($page_config['seg']) ? $this->uri->segment($page_config['seg']):1;//当前页
		$page_config['total'] = $this->Adminusercashmsg_model->get_count($where);
		$this->load->library('mypageclass');
		$this->mypageclass->initialize($page_config);
		$result = $this->Adminusercashmsg_model->get_list($page_config['perpage'],$page_config['nowindex'],$where);
		$data['list'] = $result;
		$this->load->view('adminuser/cash_msg',$data);
	}

	/**
	 * 修改保证金申请状态
	 */
	public function ajax_cash_msg(){
		$post = $this->input->post();
		$data[$post['field']] = $post['val'];
		$data['handle_user_id'] = $this->session->userdata('admin_user_id');
		$data['handle_user_name'] = $this->session->userdata('admin_user_name');
		$data['handle_add_time'] = date('Y-m-d H:i:s');
		$res = $this->Adminusercashmsg_model->edit_row($data,array('id'=>$post['id']));
		if($res){
			$this->success('操作成功','',true);
		}else{
			$this->error('操作失败','',true);
		}
	}



	/**
	 * 修改佣金申请状态
	 */
	public function ajax_cash_commision(){
		$post = $this->input->post();
		$res = $this->Adminuser_model->edit_cash_log_status($post['id']);
		if($res){
			$this->success('操作成功','',true);
		}else{
			$this->error('操作失败','',true);
		}
	}


    /**
     *
     */
    public function info(){
        $id = $this->session->userdata('admin_user_id');
        $data['row'] = $this->Adminuser_model->get_row(array('id'=>$id));
        $this->load->library('mycommonclass');
        $where = array('user_id'=>$id);
        $page_config['perpage']=20;   //每页条数
        $page_config['part']=2;//当前页前后链接数量
        $page_config['url']='admin/adminuser/info';//url
        $page_config['param'] = '';//参数
        $page_config['seg']=4;//参数取 index.php之后的段数，默认为3，即index.php/control/function/18 这种形式
        $page_config['nowindex'] = $this->uri->segment($page_config['seg']) ? $this->uri->segment($page_config['seg']):1;//当前页
        $page_config['total'] = $this->Adminuser_model->get_cash_count($where);
        $this->load->library('mypageclass');
        $this->mypageclass->initialize($page_config);
        $result = $this->Adminuser_model->get_cash_list($page_config['perpage'],$page_config['nowindex'],$where);
        $data['list'] = $result;
        $data['cash_type_value'] = array('0'=>'','1'=>'保证金','2'=>'押金');
        $data['type_value'] = array('0'=>'','1'=>'+','2'=>'-');
        $this->load->view('adminuser/admin_user_info',$data);
    }
	/**
	 * 佣金提现申请
	 */
	public function cash_commision(){
		$data = array();
		$this->load->library('mycommonclass');

		$page_config['perpage']=20;   //每页条数
		$page_config['part']=2;//当前页前后链接数量
		$page_config['url']='admin/adminuser/cash_commision';//url
		$page_config['param'] = '';//参数
		$page_config['seg']=4;//参数取 index.php之后的段数，默认为3，即index.php/control/function/18 这种形式
		$page_config['nowindex'] = $this->uri->segment($page_config['seg']) ? $this->uri->segment($page_config['seg']):1;//当前页
		$result = $this->Adminuser_model->get_cash_commision($page_config['perpage'],$page_config['nowindex']);
		$page_config['total'] = $result['total'];
		$this->load->library('mypageclass');
		$this->mypageclass->initialize($page_config);

		$data['list'] = $result['list'];
		$this->load->view('adminuser/cash_commision',$data);
	}

	/**
	 * 订单返佣记录
	 */
	public function commision_log(){
		$data = array();
		$this->load->library('mycommonclass');
	    $where = ' and a.type=1 ';
		$page_config['perpage']=30;   //每页条数
		$page_config['part']=2;//当前页前后链接数量
		$page_config['url']='admin/adminuser/commision_log';//url
		$page_config['param'] = '';//参数
		$page_config['seg']=4;//参数取 index.php之后的段数，默认为3，即index.php/control/function/18 这种形式

		$page_config['nowindex'] = $this->uri->segment($page_config['seg']) ? $this->uri->segment($page_config['seg']):1;//当前页

		$result = $this->Adminuser_model->get_cash_commision($page_config['perpage'],$page_config['nowindex'],$where);
		$page_config['total'] = $result['total'];
		$this->load->library('mypageclass');
		$this->mypageclass->initialize($page_config);

		$data['list'] = $result['list'];
		$this->load->view('adminuser/commision_log',$data);
	}






}